package com.li.controller;

import com.li.pojo.Require;
import com.li.pojo.Teacher;
import com.li.service.RequireService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Collection;

@Controller
public class RequireController {

    @Resource
    RequireService service;

    @RequestMapping("/requires")
    public String list(Model model){
        Collection<Require> requires=service.allRequire();
        model.addAttribute("requires",requires);
        return "require/list";
    }
    @GetMapping(value = "/torequire")
    public String torequire(Model model){

        return "require/add";
    }
    @RequestMapping(value = "/require/add")
    //@ResponseBody
    public String addRequire(Require require){
        if(service.addRequire(require))return "redirect:/requires";
        return "序号重复，添加失败";
    }
    @RequestMapping(value = "/require/query")
    public String queryTeacher(){
        return "";
    }

    @GetMapping("/require/{rno}")
    public String toupdateRequire(
            @PathVariable("rno")int rno, Model model){
        Require require=new Require(rno);
        require=service.queryRequire(require);
        model.addAttribute("reqs",require);
        //Collection<Class> classes=studentService.allClass();
        // model.addAttribute("classes",classes);
        return "require/update";
    }
    @RequestMapping(value = "/require/update")
    public String updateRequire(Require require){
        System.out.println("1");
        service.updateRequire(require);
        return "redirect:/requires";
    }
    @RequestMapping(value = "/delerequire/{rno}")
    public String deleteTeacher(@PathVariable("rno")int rno){
        Require require=new Require(rno);
        service.deleteRequire(require);
        return "redirect:/requires";
    }
}
